package com.hzhc.service.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.common.FileExcelUtil;
import com.hzhc.dto.UserDto;
import com.hzhc.entity.*;
import com.hzhc.enumBean.DdEnum;
import com.hzhc.enumBean.FyEnum;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.enumBean.YwOrderTypeEnum;
import com.hzhc.mapper.*;
import com.hzhc.service.*;
import com.hzhc.utils.*;
import com.hzhc.vo.YwOrderCntrVo;
import com.hzhc.vo.YwOrderSgjVo;
import com.hzhc.vo.YwOrderShipVo;
import com.hzhc.vo.YwOrderVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * 箱明细 服务实现类
 * </p>
 *
 * @author Fchenxu
 * @since 2024-05-27
 */
@Service
@RequiredArgsConstructor
public class YwOrderCntrServiceImpl extends ServiceImpl<YwOrderCntrMapper, YwOrderCntr> implements YwOrderCntrService {

    private final YwOrderMapper ywOrderMapper;
    private final CntrSizeMapper cntrSizeMapper;
    private final CntrImgFileService cntrImgFileService;
    private final CntrInfoService cntrInfoService;
    private final CntrInfoMapper cntrInfoMapper;
    private final CntrLogService cntrLogService;
    private final TrainPlanDetailMapper detailMapper;
    private final TrainPlanDetailService detailService;
    private final ProductNameMapper productNameMapper;
    private final DeclareCarMapper declareCarMapper;
    private final VehicleReservationMapper vehicleReservationMapper;

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrUpload(String orderNo, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("disable", 0).eq("status", 0));
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        if (split.length > 1) {
                            YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                            BeanUtils.copyProperties(c, ywOrderCntrVo);
                            ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "品名未填;";
                            } else {
                                if (!tradeNames.contains(ywOrderCntrVo.getGoodsName())) {
                                    errorInfo += "未找到对应品名;";
                                }
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                                errorInfo += "到站未填;";
                            } else {
                                if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                    ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                                }
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getLineOrYard())) {
                                errorInfo += "专用线或货场未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getConsignee())) {
                                errorInfo += "收货人未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceivePhone())) {
                                errorInfo += "收货联系方式未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceiveName())) {
                                errorInfo += "收货联系人未填;";
                            }
                            if (StringUtils.isEmpty(ywOrderCntrVo.getPayer())) {
                                errorInfo += "付款人未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                    ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                        errorInfo += "箱型未填;";
                                    }
                                }
                            }
                            ywOrderCntrVo.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(ywOrderCntrVo.getShipper())) {
                                ywOrderCntrVo.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    ywOrderCntrVo.setTallyState(10);
                                    ywOrderCntrVo.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(ywOrderCntrVo.getPayer())){
                                        CntrInfo cntrInfo = collect1.get(0);
                                        cntrInfo.setPayer(ywOrderCntrVo.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo);
                                    }
                                }
                            }
                            list.add(ywOrderCntrVo);
                        } else {
                            c.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(c.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getGoodsName())) {
                                errorInfo += "品名未填;";
                            } else {
                                if (!tradeNames.contains(c.getGoodsName())) {
                                    errorInfo += "未找到对应品名;";
                                }
                            }
                            if (!StrUtil.isNotBlank(c.getDestination())) {
                                errorInfo += "到站未填;";
                            } else {
                                if (!(c.getDestination().substring(c.getDestination().length() - 1).equals("站"))) {
                                    c.setDestination(c.getDestination() + "站");
                                }
                            }
                            if (!StrUtil.isNotBlank(c.getLineOrYard())) {
                                errorInfo += "专用线或货场未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getConsignee())) {
                                errorInfo += "收货人未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getReceivePhone())) {
                                errorInfo += "收货联系方式未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getReceiveName())) {
                                errorInfo += "收货联系人未填;";
                            }
                            if (StringUtils.isEmpty(c.getPayer())) {
                                errorInfo += "付款人未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (c.getCntrSize().indexOf("-") != -1) {
                                    c.setCntrSize(c.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(c.getCntrSize())) {
                                        errorInfo += "箱型不存在;";
                                    }
                                }
                            }
                            c.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(c.getShipper())) {
                                c.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(c.getCntrNo())).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    c.setTallyState(10);
                                    c.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(c.getPayer())){
                                        CntrInfo cntrInfo = collect1.get(0);
                                        cntrInfo.setPayer(c.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo);
                                    }
                                }
                            }
                            list.add(c);
                        }

                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrUpload(String orderNo, String type, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("status", 0).eq("ef_flag", "E").eq("disable", 0));

                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        if (split.length > 1) {
                            YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                            BeanUtils.copyProperties(c, ywOrderCntrVo);
                            ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if ("KJ".equals(type)) {
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                                    errorInfo += "到站未填;";
                                } else {
                                    if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                        ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                                    }
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getLineOrYard())) {
                                    errorInfo += "专用线或货场未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getConsignee())) {
                                    errorInfo += "收货人未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceivePhone())) {
                                    errorInfo += "收货联系方式未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceiveName())) {
                                    errorInfo += "收货联系人未填;";
                                }
                            }
                            if (StringUtils.isEmpty(ywOrderCntrVo.getPayer())) {
                                errorInfo += "付款人未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                    ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                        errorInfo += "箱型未填;";
                                    }
                                }
                            }
                            ywOrderCntrVo.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(ywOrderCntrVo.getShipper())) {
                                ywOrderCntrVo.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    ywOrderCntrVo.setTallyState(10);
                                    ywOrderCntrVo.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(ywOrderCntrVo.getPayer())){
                                        CntrInfo cntrInfo = collect1.get(0);
                                        cntrInfo.setPayer(ywOrderCntrVo.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo);
                                    }
                                }
                            }
                            list.add(ywOrderCntrVo);
                        } else {
                            c.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(c.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if ("KJ".equals(type)) {
                                if (!StrUtil.isNotBlank(c.getDestination())) {
                                    errorInfo += "到站未填;";
                                } else {
                                    if (!(c.getDestination().substring(c.getDestination().length() - 1).equals("站"))) {
                                        c.setDestination(c.getDestination() + "站");
                                    }
                                }
                                if (!StrUtil.isNotBlank(c.getLineOrYard())) {
                                    errorInfo += "专用线或货场未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getConsignee())) {
                                    errorInfo += "收货人未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getReceivePhone())) {
                                    errorInfo += "收货联系方式未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getReceiveName())) {
                                    errorInfo += "收货联系人未填;";
                                }
                            }
                            if (StringUtils.isEmpty(c.getPayer())) {
                                errorInfo += "付款人未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (c.getCntrSize().indexOf("-") != -1) {
                                    c.setCntrSize(c.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(c.getCntrSize())) {
                                        errorInfo += "箱型不存在;";
                                    }
                                }
                            }
                            c.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(c.getShipper())) {
                                c.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(c.getCntrNo())).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    c.setTallyState(10);
                                    c.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(c.getPayer())){
                                        CntrInfo cntrInfo = collect1.get(0);
                                        cntrInfo.setPayer(c.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo);
                                    }
                                }
                            }
                            list.add(c);
                        }

                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrDdUpload(String orderNo, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("disable", 0).eq("status", 0));
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                        BeanUtils.copyProperties(c, ywOrderCntrVo);
                        ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                        String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);

                        if (cntrInfos.size() > 0) {
                            List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                            if (collect1.size() > 0) {
                                CntrInfo cntrInfo = collect1.get(0);
                                if (StrUtil.isNotBlank(cntrInfo.getOrderNo()) && cntrInfo.getOrderNo().indexOf("ZJ") != -1
                                        && cntrInfo.getSendTransportState() == 0) {
                                    errorInfo += "发运箱子未取消发运;";
                                }
                            }
                        }
                        if (ywOrderCntrVo.getEfFlag().equals("E")) {
                            // 空重为空时，品名可以为空，不做任何处理
                        } else if ("F".equals(ywOrderCntrVo.getEfFlag())) {
                            // 空重非空且为 "F" 时，品名必须填写
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "品名未填;";
                            }
                        } else {
                            if (!tradeNames.contains(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "未找到对应品名;";
                            }
                        }
                        if (StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                            if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                            }
                        }
                        if (StrUtil.isNotBlank(ywOrderCntrVo.getInitialStation())) {
                            if (!(ywOrderCntrVo.getInitialStation().substring(ywOrderCntrVo.getInitialStation().length() - 1).equals("站"))) {
                                ywOrderCntrVo.setInitialStation(ywOrderCntrVo.getInitialStation() + "站");
                            }
                        }
                        if (!StrUtil.isNotBlank(ywOrderCntrVo.getEfFlag())) {
                            errorInfo += "空重未填;";
                        }
                        if (StringUtils.isEmpty(ywOrderCntrVo.getPayer())) {
                            errorInfo += "付款人未填;";
                        }
                        if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                            errorInfo += "箱型未填;";
                        } else {
                            if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                            }
                            if (collect.size() > 0) {
                                if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                    errorInfo += "箱型未填;";
                                }
                            }
                        }
                        ywOrderCntrVo.setErrorInfo(errorInfo);
                        list.add(ywOrderCntrVo);
                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<T> updateOldCntrById(YwOrderCntr cntr) {
        if (!(cntr.getOldCntrNo().equals(cntr.getCntrNo()))) {
            //不能与委托内其他箱号相同
            List<YwOrderCntr> cntrList = baseMapper.selectList(new QueryWrapper<YwOrderCntr>().eq("disable", 0).eq("cntr_no", cntr.getCntrNo()));
            if (cntrList.size() > 0) {
                return ResultUtil.build(ResultUtilCodeEnum.CNTR_NO_EXIST);
            }
        }
        if (cntr.getEditFlag() == 2) {
            cntr.setEditFlag(0);
            cntr.setRefugeeReason("");
        }
        if (!(cntr.getDestination().substring(cntr.getDestination().length() - 1).equals("站"))) {
            cntr.setDestination(cntr.getDestination() + "站");
        }
        boolean b = updateById(cntr);

        //修改 箱清单 装卸车清单 箱信息 箱动态 车辆预约
        List<TrainPlanDetail> details = detailMapper.selectList(new QueryWrapper<TrainPlanDetail>().eq("disable", 0)
                .eq("order_no", cntr.getOrderNo()).eq("cntr_no", cntr.getOldCntrNo()));
        if (details.size() > 0) {
            for (TrainPlanDetail detail : details) {
                detail.setCntrNo(cntr.getCntrNo());
                detail.setCntrSize(cntr.getCntrSize());
                detail.setGoods(cntr.getGoodsName());
                detail.setMdPort(cntr.getDestination());
                detail.setSealNo(cntr.getSealNo());
                detail.setConsigneeContact(cntr.getReceivePhone());
                detail.setTrainNumber(cntr.getTruckNo());
                if (StringUtils.isNotEmpty(cntr.getWeight())) {
                    detail.setWeightPred(Double.valueOf(cntr.getWeight()));
                }
                detail.setZhPort(cntr.getInitialStation());
                detail.setConsignee(cntr.getConsignee());
                detail.setConsigneeLxr(cntr.getReceiveName());
                detail.setConsigner(cntr.getShipper());
                detail.setBillNo(cntr.getBillNo());
            }
            detailService.updateBatchById(details);
        }


        CntrInfo cntrInfo = cntrInfoMapper.selectById(cntr.getOldCntrNo());

        if (cntrInfo != null) {
            CntrInfo newInfo = new CntrInfo();
            BeanUtils.copyProperties(cntrInfo, newInfo);
            newInfo.setCntrNo(cntr.getCntrNo());
            newInfo.setCntrSize(cntr.getCntrSize());
            newInfo.setGoods(cntr.getGoodsName());
            newInfo.setMdPort(cntr.getDestination());
            newInfo.setEndPort(cntr.getDestination());
            newInfo.setSealNo(cntr.getSealNo());
            newInfo.setConsigneePhone(cntr.getReceivePhone());
            newInfo.setTrainNumber(cntr.getTruckNo());
            if (StringUtils.isNotEmpty(cntr.getWeight())) {
                newInfo.setWeightPred(Double.valueOf(cntr.getWeight()));
            }
            newInfo.setZhPort(cntr.getInitialStation());
            newInfo.setConsignee(cntr.getConsignee());
            newInfo.setConsigneeLx(cntr.getReceiveName());
            newInfo.setConsigner(cntr.getShipper());
            newInfo.setBillNo(cntr.getBillNo());
            cntrInfoService.saveOrUpdate(newInfo);

            if (!(cntr.getOldCntrNo().equals(cntr.getCntrNo()))) {
                //旧的应该设为不在场 或者删掉
                cntrInfo.setStatus(1);
                cntrInfo.setBay("");
                cntrInfo.setArea("");
                cntrInfoService.updateById(cntrInfo);
            }
        }

        List<CntrLog> cntrLogs = cntrLogService.getBaseMapper().selectList(new QueryWrapper<CntrLog>().eq("disable", 0)
                .eq("cntr_no", cntr.getOldCntrNo()).eq("order_no", cntr.getOrderNo()));
        if (cntrLogs.size() > 0) {
            for (CntrLog cntrLog : cntrLogs) {
                cntrLog.setCntrNo(cntr.getCntrNo());
                cntrLog.setCntrSize(cntr.getCntrSize());
                cntrLog.setGoods(cntr.getGoodsName());
                cntrLog.setMdPort(cntr.getDestination());
                cntrLog.setEndPort(cntr.getDestination());
                cntrLog.setSealNo(cntr.getSealNo());
                cntrLog.setConsigneePhone(cntr.getReceivePhone());
                cntrLog.setTrainNumber(cntr.getTruckNo());
                if (StringUtils.isNotEmpty(cntr.getWeight())) {
                    cntrLog.setWeightPred(Double.valueOf(cntr.getWeight()));
                }
                cntrLog.setZhPort(cntr.getInitialStation());
                cntrLog.setConsignee(cntr.getConsignee());
                cntrLog.setConsigneeLx(cntr.getReceiveName());
                cntrLog.setConsigner(cntr.getShipper());
                cntrLog.setBillNo(cntr.getBillNo());
            }
            cntrLogService.updateBatchById(cntrLogs);
        }
        VehicleReservation reservation = vehicleReservationMapper.selectOne(new QueryWrapper<VehicleReservation>().eq("order_no", cntr.getOrderNo()).eq("disable", 0)
                .and(wrapper -> wrapper.eq("cntr_no", cntr.getOldCntrNo()).or().eq("cntr_no_b", cntr.getOldCntrNo())));
        if (reservation != null) {
            if (StrUtil.isNotBlank(reservation.getCntrNo()) && reservation.getCntrNo().equals(cntr.getOldCntrNo())) {
                reservation.setCntrNo(cntr.getCntrNo());
                reservation.setCntrSize(cntr.getCntrSize());
            }
            if (StrUtil.isNotBlank(reservation.getCntrNoB()) && reservation.getCntrNoB().equals(cntr.getOldCntrNo())) {
                reservation.setCntrNoB(cntr.getCntrNo());
                reservation.setCntrSizeB(cntr.getCntrSize());
            }
            vehicleReservationMapper.updateById(reservation);
        }
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public List<YwOrderCntrVo> getCntrListNoPage(YwOrderCntrVo vo) {
        return baseMapper.getCntrListNoPage(vo);
    }

    @Override
    public List<YwOrderCntrVo> getPowerCntrList(Page<YwOrderCntrVo> page, YwOrderCntrVo vo) {
        IPage<YwOrderCntrVo> list = baseMapper.getPowerCntrList(page, vo);
        return list.getRecords();
    }

    @Override
    public ResultUtil<T> updateCntrFlow(YwOrderVo vo) {
        boolean b = false;
        if (vo.getCntrList().size() > 0) {
            for (YwOrderCntr ywOrderCntr : vo.getCntrList()) {
                ywOrderCntr.setFlow(vo.getFlow());
            }
            b = updateBatchById(vo.getCntrList());
        }
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrYzsUpload(String orderNo, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("disable", 0).eq("status", 0));
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        if (split.length > 1) {
                            YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                            BeanUtils.copyProperties(c, ywOrderCntrVo);
                            ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "品名未填;";
                            } else {
                                if (!tradeNames.contains(ywOrderCntrVo.getGoodsName())) {
                                    errorInfo += "未找到对应品名;";
                                }
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                                errorInfo += "到站未填;";
                            } else {
                                if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                    ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                                }
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getLineOrYard())) {
                                errorInfo += "专用线或货场未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getConsignee())) {
                                errorInfo += "收货人未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceivePhone())) {
                                errorInfo += "收货联系方式未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceiveName())) {
                                errorInfo += "收货联系人未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                    ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                        errorInfo += "箱型未填;";
                                    }
                                }
                            }
                            ywOrderCntrVo.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(ywOrderCntrVo.getShipper())) {
                                ywOrderCntrVo.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    ywOrderCntrVo.setTallyState(10);
                                    ywOrderCntrVo.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(ywOrderCntrVo.getPayer())){
                                        CntrInfo cntrInfo1 = collect1.get(0);
                                        cntrInfo1.setPayer(ywOrderCntrVo.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo1);
                                    }
                                }
                            }
                            list.add(ywOrderCntrVo);
                        } else {
                            c.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(c.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getGoodsName())) {
                                errorInfo += "品名未填;";
                            } else {
                                if (!tradeNames.contains(c.getGoodsName())) {
                                    errorInfo += "未找到对应品名;";
                                }
                            }
                            if (!StrUtil.isNotBlank(c.getDestination())) {
                                errorInfo += "到站未填;";
                            } else {
                                if (!(c.getDestination().substring(c.getDestination().length() - 1).equals("站"))) {
                                    c.setDestination(c.getDestination() + "站");
                                }
                            }
                            if (!StrUtil.isNotBlank(c.getLineOrYard())) {
                                errorInfo += "专用线或货场未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getConsignee())) {
                                errorInfo += "收货人未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getReceivePhone())) {
                                errorInfo += "收货联系方式未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getReceiveName())) {
                                errorInfo += "收货联系人未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (c.getCntrSize().indexOf("-") != -1) {
                                    c.setCntrSize(c.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(c.getCntrSize())) {
                                        errorInfo += "箱型不存在;";
                                    }
                                }
                            }
                            c.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(c.getShipper())) {
                                c.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(c.getCntrNo())).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    c.setTallyState(10);
                                    c.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(c.getPayer())){
                                        CntrInfo cntrInfo1 = collect1.get(0);
                                        cntrInfo1.setPayer(c.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo1);
                                    }
                                }
                            }
                            list.add(c);
                        }

                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrYzsUpload(String orderNo, String type, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("disable", 0).eq("status", 0));
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        if (split.length > 1) {
                            YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                            BeanUtils.copyProperties(c, ywOrderCntrVo);
                            ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if ("KJ".equals(type)) {
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                                    errorInfo += "到站未填;";
                                } else {
                                    if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                        ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                                    }
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getLineOrYard())) {
                                    errorInfo += "专用线或货场未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getConsignee())) {
                                    errorInfo += "收货人未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceivePhone())) {
                                    errorInfo += "收货联系方式未填;";
                                }
                                if (!StrUtil.isNotBlank(ywOrderCntrVo.getReceiveName())) {
                                    errorInfo += "收货联系人未填;";
                                }
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                    ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                        errorInfo += "箱型未填;";
                                    }
                                }
                            }
                            ywOrderCntrVo.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(ywOrderCntrVo.getShipper())) {
                                ywOrderCntrVo.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    ywOrderCntrVo.setTallyState(10);
                                    ywOrderCntrVo.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(ywOrderCntrVo.getPayer())){
                                        CntrInfo cntrInfo1 = collect1.get(0);
                                        cntrInfo1.setPayer(ywOrderCntrVo.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo1);
                                    }
                                }
                            }
                            list.add(ywOrderCntrVo);
                        } else {
                            c.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(c.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if ("KJ".equals(type)) {
                                if (!StrUtil.isNotBlank(c.getDestination())) {
                                    errorInfo += "到站未填;";
                                } else {
                                    if (!(c.getDestination().substring(c.getDestination().length() - 1).equals("站"))) {
                                        c.setDestination(c.getDestination() + "站");
                                    }
                                }
                                if (!StrUtil.isNotBlank(c.getLineOrYard())) {
                                    errorInfo += "专用线或货场未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getConsignee())) {
                                    errorInfo += "收货人未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getReceivePhone())) {
                                    errorInfo += "收货联系方式未填;";
                                }
                                if (!StrUtil.isNotBlank(c.getReceiveName())) {
                                    errorInfo += "收货联系人未填;";
                                }
                            }
                            if (!StrUtil.isNotBlank(c.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (c.getCntrSize().indexOf("-") != -1) {
                                    c.setCntrSize(c.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(c.getCntrSize())) {
                                        errorInfo += "箱型不存在;";
                                    }
                                }
                            }
                            c.setErrorInfo(errorInfo);
                            if (StringUtils.isEmpty(c.getShipper())) {
                                c.setShipper("长江新丝路国际物流(武汉)有限公司");
                            }
                            if (cntrInfos.size() > 0) {
                                List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(c.getCntrNo())).collect(Collectors.toList());
                                if (collect1.size() > 0) {
                                    c.setTallyState(10);
                                    c.setSealNo(collect1.get(0).getSealNo());
                                    if(StringUtils.isNotEmpty(c.getPayer())){
                                        CntrInfo cntrInfo1 = collect1.get(0);
                                        cntrInfo1.setPayer(c.getPayer());
                                        cntrInfoMapper.updateById(cntrInfo1);
                                    }
                                }
                            }
                            list.add(c);
                        }

                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> cntrDdYzsUpload(String orderNo, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                queryWrapper.ne("tally_state", 10);//未理货的箱子，有效业务内的箱子
                //取消限制的业务
//                if (StrUtil.isNotEmpty(orderNo)){
//                    queryWrapper.eq("order_no",orderNo);
//                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrInfo> cntrInfos = cntrInfoMapper.selectList(new QueryWrapper<CntrInfo>().eq("disable", 0).eq("status", 0));
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setConsignee(StrUtil.isNotBlank(c.getConsignee()) ? c.getConsignee().trim() : "");//收货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站
                    c.setInitialStation(StrUtil.isNotBlank(c.getInitialStation()) ? c.getInitialStation().trim() : "");//发站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                        BeanUtils.copyProperties(c, ywOrderCntrVo);
                        ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                        String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);

                        if (cntrInfos.size() > 0) {
                            List<CntrInfo> collect1 = cntrInfos.stream().filter(s -> s.getCntrNo().equals(cntrNo)).collect(Collectors.toList());
                            if (collect1.size() > 0) {
                                CntrInfo cntrInfo = collect1.get(0);
                                if (StrUtil.isNotBlank(cntrInfo.getOrderNo()) && cntrInfo.getOrderNo().indexOf("ZJ") != -1
                                        && cntrInfo.getSendTransportState() == 0) {
                                    errorInfo += "发运箱子未取消发运;";
                                }
                            }
                        }
                        if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                            errorInfo += "箱号未填;";
                        }

                        if(StringUtils.isEmpty(ywOrderCntrVo.getEfFlag())){
                            errorInfo += "空重未填;";
                        }
                        if ("E".equals(ywOrderCntrVo.getEfFlag())) {
                            // 空重为空时，品名可以为空，不做任何处理
                        } else if ("F".equals(ywOrderCntrVo.getEfFlag())) {
                            // 空重非空且为 "F" 时，品名必须填写
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "品名未填;";
                            }
                        } else {
                            if (!tradeNames.contains(ywOrderCntrVo.getGoodsName())) {
                                errorInfo += "未找到对应品名;";
                            }
                        }
                        if (StrUtil.isNotBlank(ywOrderCntrVo.getDestination())) {
                            if (!(ywOrderCntrVo.getDestination().substring(ywOrderCntrVo.getDestination().length() - 1).equals("站"))) {
                                ywOrderCntrVo.setDestination(ywOrderCntrVo.getDestination() + "站");
                            }
                        }
                        if (StrUtil.isNotBlank(ywOrderCntrVo.getInitialStation())) {
                            if (!(ywOrderCntrVo.getInitialStation().substring(ywOrderCntrVo.getInitialStation().length() - 1).equals("站"))) {
                                ywOrderCntrVo.setInitialStation(ywOrderCntrVo.getInitialStation() + "站");
                            }
                        }
                        if (!StrUtil.isNotBlank(ywOrderCntrVo.getEfFlag())) {
                            errorInfo += "空重未填;";
                        }
                        if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                            errorInfo += "箱型未填;";
                        } else {
                            if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                            }
                            if (collect.size() > 0) {
                                if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                    errorInfo += "箱型未填;";
                                }
                            }
                        }
                        ywOrderCntrVo.setErrorInfo(errorInfo);
                        list.add(ywOrderCntrVo);
                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }


    @Override
    public ResultUtil<T> importCntrList(HttpServletRequest request, Long id, List<YwOrderCntr> list) {
        UserDto user = TokenUtil.getUser(request);
        YwOrder ywOrder = ywOrderMapper.selectById(id);
        List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(new QueryWrapper<YwOrderCntr>()
                .eq("disable", 0)
                .eq("order_no", ywOrder.getOrderNo()));
        if (!ywOrderCntrs.isEmpty()) {
            for (YwOrderCntr ywOrderCntr : ywOrderCntrs) {
                ywOrderCntr.setDisable(1);
            }
            updateBatchById(ywOrderCntrs);
        }
        if (YwOrderTypeEnum.TZ.getCode().equals(ywOrder.getOrderType()) || YwOrderTypeEnum.ZJ.getCode().equals(ywOrder.getOrderType())) {
            list.forEach(s -> s.setEfFlag("F"));
        } else if (YwOrderTypeEnum.SGJ.getCode().equals(ywOrder.getOrderType()) || YwOrderTypeEnum.KJ.getCode().equals(ywOrder.getOrderType())) {
            list.forEach(s -> s.setEfFlag("E"));
        }
        list.forEach(s -> s.setCreateTime(LocalDateTime.now())
                .setUserId(user.getId())
                .setOrderNo(ywOrder.getOrderNo())
                .setCompanyId(ywOrder.getCompanyId()));
        boolean b = saveBatch(list);
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public List<YwOrderCntrVo> getYwOrderCntrVoJson(Page<YwOrderCntrVo> page, YwOrderCntrVo vo) {
        IPage<YwOrderCntrVo> iPage = baseMapper.getYwOrderCntrVoJson(page, vo);
        return iPage.getRecords();
    }

    @Override
    public List<YwOrderCntr> getCntrList(Page<YwOrderCntrVo> page, YwOrderCntrVo vo) {
        QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper();
        queryWrapper.eq("disable", 0);
        queryWrapper.eq("order_no", vo.getOrderNo());
        if (StringUtils.isNotEmpty(vo.getCntrNo())) {
            queryWrapper.like("cntr_no", vo.getCntrNo());
        }
        if (vo.getTallyState() != null) {
            queryWrapper.eq("tally_state", vo.getTallyState());
        }
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<YwOrderCntrVo> getCntr(Page<YwOrderCntrVo> page, YwOrderCntrVo vo) {
        IPage<YwOrderCntrVo> list = baseMapper.getCntrList(page, vo);
        return list.getRecords();
    }

    @Override
    public ResultUtil<Map<String, List<CntrImgFile>>> uploadCntrImgZipFile(MultipartFile uploadFile, YwOrderVo vo, String cntrUploadTempFolder, String cntrUploadFolder, String cntrAccessPath) {
        try {
            if (uploadFile == null) {
                return ResultUtil.build(ResultUtilCodeEnum.FILE_NOT_UPLOAD);
            }
            if (!isCompressedFile(uploadFile)) {
                return ResultUtil.build(ResultUtilCodeEnum.FILE_FORMAT_ERRO);
            }
            //不存在则创建
            File packFile = new File(cntrUploadTempFolder);
            if (!packFile.exists()) {
                packFile.mkdirs();
            }
            String contentType = uploadFile.getContentType();
            String filename = uploadFile.getOriginalFilename();
            //将压缩包保存在指定路径
            String packFilePath = cntrUploadTempFolder + File.separator + filename;
            File file = new File(packFilePath);
            uploadFile.transferTo(file);
            //解压zip文件到临时文件夹
            String uuid = UUID.randomUUID().toString();
            //临时文件夹目录
            String tempPath = cntrUploadTempFolder + File.separator + uuid;
            ResultUtil<T> resultUtil = ZipUtils.unPackZip(file, tempPath);
            if (!Objects.equals(resultUtil.getCode(), ResultUtilCodeEnum.SUCCESS.getCode())) {
                //删除临时压缩包
                file.delete();
                return ResultUtil.build(resultUtil.getCode(), resultUtil.getMessage());
            }
            //获取压缩包名称
            if (filename != null) {
                filename = filename.substring(0, filename.lastIndexOf("."));
            }
            System.out.println("解压成功，解压目录：" + packFilePath);
            //拷贝解压后的文件到指定目录
            List<CntrImgFile> fileList = new ArrayList<>();
            //存在文件名集合
            List<CntrImgFile> fileExitList = new ArrayList<>();
            copyFile(cntrUploadTempFolder, uuid, cntrUploadFolder, vo, fileList, cntrAccessPath, fileExitList);
            //删除临时压缩包
            file.delete();
            //删除临时上传文件夹及文件夹
            deleteFiles(tempPath);
            // 保存文件信息到数据库
            cntrImgFileService.saveBatch(fileList);
            Map<String, List<CntrImgFile>> listMap = fileList.stream().collect(Collectors.groupingBy(CntrImgFile::getCntrNo));
            listMap.put("fileExitList", fileExitList);
            return ResultUtil.build(listMap, ResultUtilCodeEnum.SUCCESS);
        } catch (Exception e) {
//            throw new RuntimeException(e);
            e.printStackTrace();
            return ResultUtil.build(ResultUtilCodeEnum.FILE_UPLOAD_FAIL);
        }
    }

    @Override
    public void exportFile(HttpServletRequest request, HttpServletResponse response, String exportExcelPath) {
        Map<String, Object> map = new HashMap<>();
        TemplateExportParams params = new TemplateExportParams(exportExcelPath);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        FileExcelUtil.downloadExcelIo(workbook, request, response, "发运委托清单");
    }

    @Override
    public void exportFile1(HttpServletRequest request, HttpServletResponse response, String exportExcelPath) {
        Map<String, Object> map = new HashMap<>();
        TemplateExportParams params = new TemplateExportParams(exportExcelPath);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        FileExcelUtil.downloadExcelIo(workbook, request, response, "提箱委托清单");
    }

    @Override
    public ResultUtil<T> delBatchCntrRet(YwOrderVo vo) {
        boolean b = false;
        if (vo.getCntrList().size() > 0) {
            long count = vo.getCntrList().stream().filter(s -> s.getTallyState() != 0).count();
            if (count > 0) {
                return ResultUtil.build(ResultUtilCodeEnum.CNTR_TALLY_YET);
            }

            List<CntrInfo> cntrInfos = new ArrayList<>();

            for (YwOrderCntr ywOrderCntr : vo.getCntrList()) {
                ywOrderCntr.setDisable(1);
                ywOrderCntr.setUpdateTime(vo.getUpdateTime());
                ywOrderCntr.setUpdateUserId(vo.getUpdateUserId());

                long tzCntr = vo.getCntrList().stream().filter(s -> s.getOrderNo().indexOf("TZ") != -1).count();
                if (!(tzCntr > 0)) {
                    CntrInfo cntrInfo = cntrInfoMapper.getCntrInfoById(ywOrderCntr.getCntrNo());
                    if (cntrInfo != null) {
                        CntrInfo cntrInfo1 = deleteCntrInfo(cntrInfo);
                        cntrInfos.add(cntrInfo1);
                    }
                    if (StringUtils.isNotEmpty(cntrInfo.getCntrWorkRemark())
                            && !(FyEnum.DSL.getName().equals(cntrInfo.getCntrWorkRemark()) || FyEnum.YSL.getName().equals(cntrInfo.getCntrWorkRemark()))) {
                        return ResultUtil.build(ResultUtilCodeEnum.CNTR_IS_INYARD);
                    }
                }

            }
            if(cntrInfos.size()>0){
                cntrInfoService.updateBatchById(cntrInfos);
            }

            b = updateBatchById(vo.getCntrList());

            //删除车辆预约和进卡记录
            List<String> delCntrList = vo.getCntrList().stream().map(YwOrderCntr::getCntrNo).collect(Collectors.toList());//待删除箱子的集装箱号
            List<VehicleReservation> vehicleReservations = vehicleReservationMapper.selectList(new QueryWrapper<VehicleReservation>().eq("disable", 0)
                    .eq("order_no", vo.getCntrList().get(0).getOrderNo())
                    .and(wrapper -> wrapper.in("cntr_no", delCntrList).or().in("cntr_no_b", delCntrList)));

            //判断一下 哪个是要删除的车辆预约数据
            List<VehicleReservation> delVehicleReservations = new ArrayList<>();
            if (vehicleReservations.size() > 0) {
                for (VehicleReservation vehicleReservation : vehicleReservations) {
                    boolean flag = true;
                    if (StringUtils.isNotEmpty(vehicleReservation.getCntrNo())) {
                        if (!delCntrList.contains(vehicleReservation.getCntrNo())) {
                            flag = false;
                        }
                    }
                    if (StringUtils.isNotEmpty(vehicleReservation.getCntrNoB())) {
                        if (!delCntrList.contains(vehicleReservation.getCntrNoB())) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        vehicleReservation.setDisable(1);
                        delVehicleReservations.add(vehicleReservation);
                    }
                }

                if (delVehicleReservations.size() > 0) {
                    List<Long> longList = delVehicleReservations.stream().map(VehicleReservation::getId).collect(Collectors.toList());
                    vehicleReservationMapper.deleteIds(longList);

                    List<DeclareCar> declareCars = declareCarMapper.selectList(new QueryWrapper<DeclareCar>().eq("disable", 0)
                            .and(wrapper -> wrapper.in("vehicle_id", longList).or().in("vehicle_id_b", longList)));
                    if (declareCars.size() > 0) {
                        for (DeclareCar declareCar : declareCars) {
                            if (declareCar.getVehicleId() != null) {
                                if (longList.contains(declareCar.getVehicleId())) {
                                    declareCar.setVehicleId(null);
                                }
                            }
                            if (declareCar.getVehicleIdB() != null) {
                                if (longList.contains(declareCar.getVehicleIdB())) {
                                    declareCar.setVehicleIdB(null);
                                }
                            }
                            if (declareCar.getVehicleId() == null && declareCar.getVehicleIdB() == null) {
                                declareCar.setDisable(1);
                            }
                            declareCarMapper.updateById(declareCar);
                        }
                    }
                }


            }

            //删除进卡记录
            List<CntrLog> cntrLogs = cntrLogService.getBaseMapper().selectList(new QueryWrapper<CntrLog>().eq("disable", 0)
                    .eq("order_no", vo.getCntrList().get(0).getOrderNo()).eq("remark", "集装箱进卡").in("cntr_no", delCntrList));
            if (cntrLogs.size() > 0) {
                for (CntrLog cntrLog : cntrLogs) {
                    cntrLog.setDisable(1);
                }
                cntrLogService.updateBatchById(cntrLogs);
            }

        }
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    private CntrInfo deleteCntrInfo(CntrInfo cntrInfo) {
        //TODO

        CntrInfo cntrInfo1 = new CntrInfo();
        BeanUtils.copyProperties(cntrInfo, cntrInfo1);
        cntrInfo1.setCntrWorkRemark(null);
        cntrInfo1.setCntrWorkRemarkB(null);
        cntrInfo1.setCntrRemark("");
        cntrInfo1.setStartPort("");
        cntrInfo1.setEndPort("");
        cntrInfo1.setSpecialWay("");
        cntrInfo1.setConsigneeLx("");
        cntrInfo1.setConsigneePhone("");
        cntrInfo1.setConsignee("");
        cntrInfo1.setConsigner("");
        cntrInfo1.setMdPort("");
        cntrInfo1.setZhPort("");
        cntrInfo1.setOrderNo("");
        cntrInfo1.setCarNo("");
        cntrInfo1.setRemark("");
        cntrInfo1.setSealNo("");
        cntrInfo1.setGoods("");
        cntrInfo1.setWeightPred(null);
        return cntrInfo1;
    }

    @Override
    public ResultUtil<T> updateCntrById(YwOrderCntr cntr) {
        if (cntr.getEditFlag() == 2) {
            cntr.setEditFlag(0);
            cntr.setRefugeeReason("");
        }
        if (!(cntr.getDestination().substring(cntr.getDestination().length() - 1).equals("站"))) {
            cntr.setDestination(cntr.getDestination() + "站");
        }
        boolean b = updateById(cntr);

        //修改 箱清单 装卸车清单 箱信息 箱动态 车辆预约
        List<TrainPlanDetail> details = detailMapper.selectList(new QueryWrapper<TrainPlanDetail>().eq("disable", 0)
                .eq("order_no", cntr.getOrderNo()).eq("cntr_no", cntr.getCntrNo()));
        if (details.size() > 0) {
            for (TrainPlanDetail detail : details) {
                detail.setCntrSize(cntr.getCntrSize());
                detail.setGoods(cntr.getGoodsName());
                detail.setMdPort(cntr.getDestination());
                detail.setSealNo(cntr.getSealNo());
                detail.setConsigneeContact(cntr.getReceivePhone());
                detail.setTrainNumber(cntr.getTruckNo());
                if (StringUtils.isNotEmpty(cntr.getWeight())) {
                    detail.setWeightPred(Double.valueOf(cntr.getWeight()));
                }
                detail.setZhPort(cntr.getInitialStation());
                detail.setConsignee(cntr.getConsignee());
                detail.setConsigneeLxr(cntr.getReceiveName());
                detail.setConsigner(cntr.getShipper());
                detail.setBillNo(cntr.getBillNo());
            }
            detailService.updateBatchById(details);
        }


        CntrInfo cntrInfo = cntrInfoMapper.selectById(cntr.getCntrNo());
        if (cntrInfo != null) {
            cntrInfo.setCntrSize(cntr.getCntrSize());
            cntrInfo.setGoods(cntr.getGoodsName());
            cntrInfo.setMdPort(cntr.getDestination());
            cntrInfo.setEndPort(cntr.getDestination());
            cntrInfo.setSealNo(cntr.getSealNo());
            cntrInfo.setConsigneePhone(cntr.getReceivePhone());
            cntrInfo.setTrainNumber(cntr.getTruckNo());
            if (StringUtils.isNotEmpty(cntr.getWeight())) {
                cntrInfo.setWeightPred(Double.valueOf(cntr.getWeight()));
            }
            cntrInfo.setZhPort(cntr.getInitialStation());
            cntrInfo.setConsignee(cntr.getConsignee());
            cntrInfo.setConsigneeLx(cntr.getReceiveName());
            cntrInfo.setConsigner(cntr.getShipper());
            cntrInfo.setBillNo(cntr.getBillNo());
            cntrInfoMapper.updateById(cntrInfo);
        }

        List<CntrLog> cntrLogs = cntrLogService.getBaseMapper().selectList(new QueryWrapper<CntrLog>().eq("disable", 0)
                .eq("cntr_no", cntr.getCntrNo()).eq("order_no", cntr.getOrderNo()));
        if (cntrLogs.size() > 0) {
            for (CntrLog cntrLog : cntrLogs) {
                cntrLog.setCntrSize(cntr.getCntrSize());
                cntrLog.setGoods(cntr.getGoodsName());
                cntrLog.setMdPort(cntr.getDestination());
                cntrLog.setEndPort(cntr.getDestination());
                cntrLog.setSealNo(cntr.getSealNo());
                cntrLog.setConsigneePhone(cntr.getReceivePhone());
                cntrLog.setTrainNumber(cntr.getTruckNo());
                if (StringUtils.isNotEmpty(cntr.getWeight())) {
                    cntrLog.setWeightPred(Double.valueOf(cntr.getWeight()));
                }
                cntrLog.setZhPort(cntr.getInitialStation());
                cntrLog.setConsignee(cntr.getConsignee());
                cntrLog.setConsigneeLx(cntr.getReceiveName());
                cntrLog.setConsigner(cntr.getShipper());
                cntrLog.setBillNo(cntr.getBillNo());
            }
            cntrLogService.updateBatchById(cntrLogs);
        }
        VehicleReservation reservation = vehicleReservationMapper.selectOne(new QueryWrapper<VehicleReservation>().eq("order_no", cntr.getOrderNo()).eq("disable", 0)
                .and(wrapper -> wrapper.eq("cntr_no", cntr.getCntrNo()).or().eq("cntr_no_b", cntr.getCntrNo())));
        if (reservation != null) {
            if (StrUtil.isNotBlank(reservation.getCntrNo()) && reservation.getCntrNo().equals(cntr.getCntrNo())) {
                reservation.setCntrSize(cntr.getCntrSize());
            }
            if (StrUtil.isNotBlank(reservation.getCntrNoB()) && reservation.getCntrNoB().equals(cntr.getCntrNo())) {
                reservation.setCntrSizeB(cntr.getCntrSize());
            }
            vehicleReservationMapper.updateById(reservation);
        }
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> addCntrRet(YwOrderCntr cntr) {
        YwOrder ywOrder = ywOrderMapper.selectOne(new QueryWrapper<YwOrder>().eq("disable", 0).eq("order_no", cntr.getOrderNo()));
        if (ywOrder != null) {
            cntr.setCompanyId(ywOrder.getCompanyId());
        }
        if (!(cntr.getDestination().substring(cntr.getDestination().length() - 1).equals("站"))) {
            cntr.setDestination(cntr.getDestination() + "站");
        }
        if("ZJ".equals(ywOrder.getOrderType()) || "KJ".equals(ywOrder.getOrderType())){
            CntrInfo cntrInfo = cntrInfoMapper.selectById(cntr.getCntrNo());
            if(cntrInfo!=null && cntrInfo.getStatus()==0){
                cntr.setTallyState(10);
            }
        }
        boolean b = save(cntr);
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public void exportSgjFile(HttpServletRequest request, HttpServletResponse response, String exportExcelPath) {
        Map<String, Object> map = new HashMap<>();
        TemplateExportParams params = new TemplateExportParams(exportExcelPath);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        FileExcelUtil.downloadExcelIo(workbook, request, response, "导入清单模板");
    }

    @Override
    public ResultUtil<List<YwOrderCntrVo>> sgjCntrUpload(String orderNo, MultipartFile file) {
        List<YwOrderCntrVo> list = new ArrayList<YwOrderCntrVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderCntrVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderCntrVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 1, 1, YwOrderCntrVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                if (StrUtil.isNotEmpty(orderNo)) {
                    queryWrapper.eq("order_no", orderNo);
                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<CntrSize> cntrSizes = cntrSizeMapper.selectList(new QueryWrapper<CntrSize>().eq("disable", 0));
                List<String> collect = new ArrayList<>();
                if (cntrSizes.size() > 0) {
                    collect = cntrSizes.stream().map(CntrSize::getCntrName).collect(Collectors.toList());
                }
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderCntrVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isBlank(c.getCntrNo())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }
                    c.setShipper(StrUtil.isNotBlank(c.getShipper()) ? c.getShipper().trim() : "");//发货人去空
                    c.setDestination(StrUtil.isNotBlank(c.getDestination()) ? c.getDestination().trim() : "");//到站

                    String[] split = c.getCntrNo().split("/");
                    for (String cntrNo : split) {
                        if (split.length > 1) {
                            YwOrderCntrVo ywOrderCntrVo = new YwOrderCntrVo();
                            BeanUtils.copyProperties(c, ywOrderCntrVo);
                            ywOrderCntrVo.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(ywOrderCntrVo.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (ywOrderCntrVo.getCntrSize().indexOf("-") != -1) {
                                    ywOrderCntrVo.setCntrSize(ywOrderCntrVo.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(ywOrderCntrVo.getCntrSize())) {
                                        errorInfo += "箱型未填;";
                                    }
                                }
                            }
                            ywOrderCntrVo.setErrorInfo(errorInfo);
                            list.add(ywOrderCntrVo);
                        } else {
                            c.setCntrNo(StrUtil.isNotBlank(cntrNo) ? cntrNo.replace(" ", "").trim() : "");//箱号去空
                            String errorInfo = checkCntr(cntrList, ywOrderCntrs, cntrNo);
                            if (!StrUtil.isNotBlank(c.getCntrNo())) {
                                errorInfo += "箱号未填;";
                            }
                            if (!StrUtil.isNotBlank(c.getCntrSize())) {
                                errorInfo += "箱型未填;";
                            } else {
                                if (c.getCntrSize().indexOf("-") != -1) {
                                    c.setCntrSize(c.getCntrSize().split("-")[0]);
                                }
                                if (collect.size() > 0) {
                                    if (!collect.contains(c.getCntrSize())) {
                                        errorInfo += "箱型不存在;";
                                    }
                                }
                            }
                            c.setErrorInfo(errorInfo);
                            list.add(c);
                        }

                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<T> importSgjCntrList(HttpServletRequest request, YwOrderVo vo) {
        UserDto user = TokenUtil.getUser(request);
        YwOrder ywOrder = ywOrderMapper.selectById(vo.getId());
        if (ywOrder.getFinishFlag().equals(10)) {
            return ResultUtil.build(400, "数据已完工");
        }
        List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(new QueryWrapper<YwOrderCntr>()
                .eq("disable", 0)
                .eq("order_no", ywOrder.getOrderNo()));
        List<String> tallyCntr = new ArrayList<>();
        if (!ywOrderCntrs.isEmpty()) {
            for (YwOrderCntr ywOrderCntr : ywOrderCntrs) {
                //已理货的箱子跳过删除
                if (ywOrderCntr.getTallyState().equals(10)) {
                    tallyCntr.add(ywOrderCntr.getCntrNo());
                    continue;
                }
                ywOrderCntr.setDisable(1);
            }
            updateBatchById(ywOrderCntrs);
        }
        //获取要执行新增的箱子
        List<YwOrderCntr> untallyYwOrderCntrList = new ArrayList<>();
        for (YwOrderCntr ywOrderCntr : vo.getCntrList()) {
            if (!tallyCntr.contains(ywOrderCntr.getCntrNo())) {
                untallyYwOrderCntrList.add(ywOrderCntr);
            }
        }
        List<CntrInfo> cntrInfos = new ArrayList<>();
        List<CntrLog> cntrLogs = new ArrayList<>();
        for (YwOrderCntr ywOrderCntr : untallyYwOrderCntrList) {
            ywOrderCntr.setCreateTime(LocalDateTime.now());
            ywOrderCntr.setUserId(user.getId());
            ywOrderCntr.setOrderNo(ywOrder.getOrderNo());
            ywOrderCntr.setCompanyId(ywOrder.getCompanyId());
            ywOrderCntr.setEfFlag("F");
            CntrInfo cntrInfo = cntrInfoMapper.getCntrInfoById(ywOrderCntr.getCntrNo());
            CntrLog cntrLog = new CntrLog();
            if (cntrInfo != null) {
                cntrInfo.setOrderNo(ywOrder.getOrderNo());
                cntrInfo.setCntrWorkRemark(DdEnum.DSL.getName());
                cntrInfo.setLockFlag(1);
                cntrInfo.setRemark("提交受理");
                cntrInfo.setLockStart(LocalDateTime.now());
                cntrInfo.setCompanyId(vo.getCompanyId());
                if (!("散改集箱").equals(cntrInfo.getCntrRemark())) {
                    cntrInfo.setCntrRemark("散改集箱");
//                    cntrInfo.setCompanyId(ywOrder.getCompanyId());
                    cntrInfos.add(cntrInfo);
                    BeanUtils.copyProperties(cntrInfo, cntrLog);
                    cntrLog.setCreatetime(LocalDateTime.now());
                    cntrLogs.add(cntrLog);
                }
            } else {
                CntrInfo cntrInfo1 = new CntrInfo();
                cntrInfo1.setOrderNo(ywOrder.getOrderNo());
                cntrInfo1.setCntrNo(ywOrderCntr.getCntrNo());
                cntrInfo1.setCntrSize(ywOrderCntr.getCntrSize());
                cntrInfo1.setStatus(1);
                cntrInfo1.setLockFlag(1);
                cntrInfo1.setRemark("提交受理");
                cntrInfo1.setLockStart(LocalDateTime.now());
                cntrInfo1.setCreatetime(LocalDateTime.now());
                cntrInfo1.setCntrWorkRemark(DdEnum.DSL.getName());
//                cntrInfo1.setCompanyId(ywOrder.getCompanyId());
                if (!("散改集箱").equals(cntrInfo1.getCntrRemark())) {
                    cntrInfo1.setCntrRemark("散改集箱");
                    cntrInfos.add(cntrInfo1);
                    BeanUtils.copyProperties(cntrInfo1, cntrLog);
                    cntrLog.setCreatetime(LocalDateTime.now());
                    cntrLogs.add(cntrLog);
                }
            }
        }
        if (cntrInfos.size() > 0) {
            cntrInfoService.saveOrUpdateBatch(cntrInfos);
        }
        if (cntrLogs.size() > 0) {
            cntrLogService.saveOrUpdateBatch(cntrLogs);
        }
        boolean b = true;
        if (!untallyYwOrderCntrList.isEmpty()) {
            b = saveBatch(untallyYwOrderCntrList);
        }
        if (b) {
            if (tallyCntr.isEmpty()) {
                return ResultUtil.ok();
            } else {
                return ResultUtil.build(200, ResultUtilCodeEnum.SUCCESS.getMessage() + ",箱子" + tallyCntr.stream().collect(Collectors.joining(",")) + "已理货无法处理");
            }
        } else {
            if (tallyCntr.isEmpty()) {
                return ResultUtil.fail();
            } else {
                return ResultUtil.build(400, ResultUtilCodeEnum.FAIL.getMessage() + ",箱子" + tallyCntr.stream().collect(Collectors.joining(",")) + "已理货无法处理");
            }
        }
    }

    @Override
    public ResultUtil<List<YwOrderSgjVo>> sgjHzCntrUpload(String orderNo, MultipartFile file) {
        List<YwOrderSgjVo> list = new ArrayList<YwOrderSgjVo>();
        List<String> cntrList = new ArrayList<String>();
        ResultUtil<List<YwOrderSgjVo>> build = new ResultUtil<>();
        if (file != null) {
            try {
                List<YwOrderSgjVo> planCntrVos = EasypoiExcelUtils.importExcel(file, 0, 1, YwOrderSgjVo.class);
                QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("disable", 0);
                if (StrUtil.isNotEmpty(orderNo)) {
                    queryWrapper.eq("order_no", orderNo);
                }
                List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(queryWrapper);
                List<ProductName> productNames = productNameMapper.selectList(new QueryWrapper<ProductName>().eq("disable", 0));
                List<String> tradeNames = new ArrayList<>();
                if (!productNames.isEmpty()) {
                    tradeNames = productNames.stream().map(ProductName::getTradeName).collect(Collectors.toList());
                }
                for (YwOrderSgjVo c : planCntrVos) { //校验数据
                    if (ObjectUtil.isEmpty(c) || StrUtil.isAllBlank(c.getCntrNo(), c.getCntrNoB())) {
                        c.setErrorInfo("文件中有空数据;");
                        list.add(c);
                        break;
                    }

                    YwOrderSgjVo ywOrderSgjVo = new YwOrderSgjVo();
                    YwOrderSgjVo ywOrderSgjVo1 = new YwOrderSgjVo();
                    if (StringUtils.isNotEmpty(c.getCntrNo()) && StringUtils.isNotEmpty(c.getCntrNoB())) {
                        BeanUtils.copyProperties(c, ywOrderSgjVo);
                        BeanUtils.copyProperties(c, ywOrderSgjVo1);
                        ywOrderSgjVo.setCntrNoB("");
                        ywOrderSgjVo.setCntrNo(c.getCntrNo().replace(" ", "").trim());//箱号去空
                        ywOrderSgjVo1.setCntrNo(c.getCntrNoB().replace(" ", "").trim());//箱号去空
                        ywOrderSgjVo1.setCntrNoB("");
                        String errorInfo = checkCntrShip(cntrList, ywOrderCntrs, c.getCntrNo());

                        errorInfo += checkCntrShip(cntrList, ywOrderCntrs, c.getCntrNoB());
                        if (StrUtil.isAllBlank(ywOrderSgjVo.getCntrNo(), ywOrderSgjVo.getCntrNoB())) {
                            errorInfo += "箱号未填;";
                        }
                        if (!StrUtil.isNotBlank(ywOrderSgjVo.getGoodsName())) {
                            errorInfo += "货名未填;";
                        } else {
                            if (!tradeNames.contains(ywOrderSgjVo.getGoodsName())) {
                                errorInfo += "未找到对应品名;";
                            }
                        }
                        ywOrderSgjVo.setErrorInfo(errorInfo);
                        ywOrderSgjVo.setJzWeight(StringUtils.isNotEmpty(ywOrderSgjVo.getJzWeight()) ? new BigDecimal(ywOrderSgjVo.getJzWeight()).divide(new BigDecimal(2)).toString() : "0");
                        ywOrderSgjVo.setMzWeight(StringUtils.isNotEmpty(ywOrderSgjVo.getMzWeight()) ? new BigDecimal(ywOrderSgjVo.getMzWeight()).divide(new BigDecimal(2)).toString() : "0");
                        ywOrderSgjVo.setKzWeight(StringUtils.isNotEmpty(ywOrderSgjVo.getKzWeight()) ? new BigDecimal(ywOrderSgjVo.getKzWeight()).divide(new BigDecimal(2)).toString() : "0");

                        ywOrderSgjVo1.setJzWeight(ywOrderSgjVo.getJzWeight());
                        ywOrderSgjVo1.setMzWeight(ywOrderSgjVo.getMzWeight());
                        ywOrderSgjVo1.setKzWeight(ywOrderSgjVo.getKzWeight());
                        list.add(ywOrderSgjVo);
                        list.add(ywOrderSgjVo1);
                    } else if (StringUtils.isNotEmpty(c.getCntrNo())) {
                        BeanUtils.copyProperties(c, ywOrderSgjVo);
                        ywOrderSgjVo.setCntrNo(c.getCntrNo().replace(" ", "").trim());//箱号去空
                        String errorInfo = checkCntrShip(cntrList, ywOrderCntrs, c.getCntrNo());
                        if (StrUtil.isAllBlank(ywOrderSgjVo.getCntrNo())) {
                            errorInfo += "箱号未填;";
                        }
                        if (!StrUtil.isNotBlank(ywOrderSgjVo.getGoodsName())) {
                            errorInfo += "货名未填;";
                        } else {
                            if (!tradeNames.contains(ywOrderSgjVo.getGoodsName())) {
                                errorInfo += "未找到对应品名;";
                            }
                        }
                        ywOrderSgjVo.setErrorInfo(errorInfo);
                        list.add(ywOrderSgjVo);
                    } else if (StringUtils.isNotEmpty(c.getCntrNoB())) {
                        BeanUtils.copyProperties(c, ywOrderSgjVo1);
                        ywOrderSgjVo1.setCntrNo(c.getCntrNoB().replace(" ", "").trim());//箱号去空
                        String errorInfo = checkCntrShip(cntrList, ywOrderCntrs, c.getCntrNoB());
                        if (StrUtil.isAllBlank(ywOrderSgjVo1.getCntrNoB())) {
                            errorInfo += "箱号未填;";
                        }
                        if (!StrUtil.isNotBlank(ywOrderSgjVo1.getGoodsName())) {
                            errorInfo += "货名未填;";
                        } else {
                            if (!tradeNames.contains(ywOrderSgjVo1.getGoodsName())) {
                                errorInfo += "未找到对应品名;";
                            }
                        }
                        ywOrderSgjVo1.setCntrNoB("");
                        ywOrderSgjVo1.setErrorInfo(errorInfo);
                        list.add(ywOrderSgjVo1);
                    }
                }
                build = ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return build;
    }

    @Override
    public ResultUtil<T> importSgjCntrShipList(HttpServletRequest request, Long id, List<YwOrderCntr> list) {
        YwOrder ywOrder = ywOrderMapper.selectById(id);
        List<YwOrderCntr> ywOrderCntrs = baseMapper.selectList(new QueryWrapper<YwOrderCntr>()
                .eq("disable", 0)
                .eq("order_no", ywOrder.getOrderNo()));
        boolean b = false;
        if (!ywOrderCntrs.isEmpty()) {
            for (YwOrderCntr ywOrderCntr : ywOrderCntrs) {
                List<YwOrderCntr> collect = list.stream()
                        .filter(c -> c.getCntrNo().equals(ywOrderCntr.getCntrNo())).collect(Collectors.toList());
                if (collect.size() > 0) {
                    ywOrderCntr.setShipName(collect.get(0).getShipName());
                    ywOrderCntr.setJzWeight(collect.get(0).getJzWeight());
                    ywOrderCntr.setKzWeight(collect.get(0).getKzWeight());
                    ywOrderCntr.setGoodsName(collect.get(0).getGoodsName());
                    ywOrderCntr.setMzWeight(collect.get(0).getMzWeight());
                    ywOrderCntr.setShipFh(collect.get(0).getShipFh());
                    ywOrderCntr.setShipSh(collect.get(0).getShipSh());
                    ywOrderCntr.setPzGateTime(collect.get(0).getPzGateTime());
                    ywOrderCntr.setMzGateTime(collect.get(0).getMzGateTime());
                    ywOrderCntr.setRemark(collect.get(0).getRemark());
                    ywOrderCntr.setHzdrFlag(1);//回重导入标志
                    ywOrderCntr.setXPort(collect.get(0).getXPort());
                    ywOrderCntr.setTruckNo(collect.get(0).getTruckNo());
                }
            }
            b = updateBatchById(ywOrderCntrs);
        }
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    @Override
    public List<YwOrderCntrVo> getCntrByShipName(Page<YwOrderCntrVo> page, YwOrderCntrVo vo) {
        IPage<YwOrderCntrVo> orderPage = baseMapper.getCntrByShipName(page, vo);
        return orderPage.getRecords();
    }


    @Override
    public List<YwOrderCntrVo> getCntrByShip(YwOrderShipVo ywOrderShipVo) {
        List<YwOrderCntrVo> list = baseMapper.getCntrByShip(ywOrderShipVo);
        return list;
    }

    @Override
    public void exportSgjHzFile(HttpServletRequest request, HttpServletResponse response, String exportExcelHzPath) {
        Map<String, Object> map = new HashMap<>();
        TemplateExportParams params = new TemplateExportParams(exportExcelHzPath);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        FileExcelUtil.downloadExcelIo(workbook, request, response, "散改集回重模板");
    }


    private void deleteFiles(String tempPath) throws IOException {
        // 路径
        Path directory = Paths.get(tempPath);
        Stream<Path> stream = Files.walk(directory).sorted(Comparator.reverseOrder());
        stream.forEach(path -> {
            try {
                Files.delete(path);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 拷贝解压后的文件到指定目录
     *
     * @param packFileStr
     * @param uuid
     * @param targetFileUrl
     * @param vo
     * @param fileList
     * @param cntrAccessPath
     * @throws IOException
     */
    private void copyFile(String packFileStr, String uuid, String targetFileUrl, YwOrderVo vo, List<CntrImgFile> fileList,
                          String cntrAccessPath, List<CntrImgFile> fileExitList) throws IOException {

        File zipFile = new File(packFileStr + File.separator + uuid);
        List<File> allFileList = new ArrayList<>();
        if (zipFile.exists()) {
            //获取解压后的文件列表
            getAllFile(zipFile, allFileList);
        }
        for (File f : allFileList) {
            Path sourcePath = f.toPath();
//                System.out.println("file path:======"+f.getPath());
            String splitFlag = File.separator;
            if (!"/".equals(splitFlag)) {
                splitFlag = "\\\\";
            }
            String[] pathArr = f.getPath().split(splitFlag);
            String cntrNo = "";
            for (int i = 0; i < pathArr.length; i++) {
                if (CheckUtils.checkCntrNo(pathArr[i])) {
                    cntrNo = pathArr[i];
                    break;
                }
            }
            Path targetPath = Paths.get(targetFileUrl + File.separator + vo.getOrderNo() + File.separator + cntrNo, f.getName());
            System.out.println("file targetPath:======" + targetPath.toString());
            File targetFile = new File(targetFileUrl + File.separator + vo.getOrderNo() + File.separator + cntrNo, f.getName());
            File targetParentFile = targetFile.getParentFile();
            while (!targetParentFile.exists()) {
                targetParentFile.mkdirs();
                targetParentFile = targetParentFile.getParentFile();
            }

            // 复制文件到指定目录
            if (!Files.exists(targetPath)) {
                Files.copy(sourcePath, targetPath);
                CntrImgFile cntrImgFile = new CntrImgFile();
                cntrImgFile.setOrderNo(vo.getOrderNo());
                cntrImgFile.setFileSubfolder(cntrAccessPath.replaceAll("\\*", "") + vo.getOrderNo() + File.separator + cntrNo);
                cntrImgFile.setFileName(f.getName());
                cntrImgFile.setFileType("KHWT");
                cntrImgFile.setCreateTime(LocalDateTime.now());
                cntrImgFile.setCreateId(vo.getUserId());
                cntrImgFile.setCreateUser(vo.getUserName());
                cntrImgFile.setCntrNo(cntrNo);
                cntrImgFile.setFileUrl(cntrImgFile.getFileSubfolder() + File.separator + cntrImgFile.getFileName());
                fileList.add(cntrImgFile);
            } else {
                CntrImgFile cntrImgFile = new CntrImgFile();
                cntrImgFile.setFileName(f.getName());
                fileExitList.add(cntrImgFile);
            }
        }
    }

    private void getAllFile(File fileInput, List<File> allFileList) {
        File[] files = fileInput.listFiles();
        //遍历文件列表，逐个上传
        if (files == null) {
            return;
        }
        for (File f : files) {
            if (f.isDirectory()) {
                getAllFile(f, allFileList);
            } else {
                allFileList.add(f);
            }
        }
    }

    private String checkCntr(List<String> cntrList, List<YwOrderCntr> ywOrderCntrs, String cntrNo) {
//        boolean checkDigit = CheckUtils.checkDigit(cntrNo);
//        if (!checkDigit) {
//            return "箱号格式不正确;";
//        }
        //箱号校验暂时仅校验位数
        if (cntrNo == null || cntrNo.trim().length() != 11) {
            return "箱号格式不正确;";
        }
        if (cntrList.contains(cntrNo)) {
            return "箱号重复;";
        }
        boolean isCntrNo = ywOrderCntrs.stream().anyMatch(item -> cntrNo.equals(item.getCntrNo()));
        if (isCntrNo) {
            return "该箱号已存在;";
        }
        cntrList.add(cntrNo);
        return "";
    }

    private String checkCntrShip(List<String> cntrList, List<YwOrderCntr> ywOrderCntrs, String cntrNo) {
        //箱号校验暂时仅校验位数
        if (cntrNo == null || cntrNo.trim().length() != 11) {
            return "箱号格式不正确;";
        }
        if (cntrList.contains(cntrNo)) {
            return "箱号重复;";
        }
        boolean isCntrNo = ywOrderCntrs.stream().anyMatch(item -> cntrNo.equals(item.getCntrNo()));
        if (!isCntrNo) {
            return "该箱号计划中不存在;";
        }
        List<YwOrderCntr> collect = ywOrderCntrs.stream().filter(item -> cntrNo.equals(item.getCntrNo())).collect(Collectors.toList());
        if (collect.size() > 0) {
            if (collect.get(0).getTallyState() == 0) {
                return "箱未理货;";
            }
        }
        cntrList.add(cntrNo);
        return "";
    }

    // 可能的压缩文件后缀列表
    private static final String FILE_EXTENSIONS = "zip";
    private static final String FILE_EXTENSIONS_RAR = "rar";

    /**
     * 校验上传文件是否为压缩文件
     *
     * @param file
     * @return
     */
    public static boolean isCompressedFile(MultipartFile file) {
        String fileName = file.getOriginalFilename();
        return fileName != null && fileName.endsWith(FILE_EXTENSIONS);
    }

    @Override
    public YwOrderCntr getCntrByorderNoCntrNo(String orderNo, String cntrNo) {
        // TODO Auto-generated method stub
        QueryWrapper<YwOrderCntr> queryWrapper = new QueryWrapper<YwOrderCntr>();
        queryWrapper.eq("order_no", orderNo);
        queryWrapper.eq("cntr_no", cntrNo);
        queryWrapper.eq("disable", 0);
        List<YwOrderCntr> list = baseMapper.selectList(queryWrapper);
        if (list.size() > 0)
            return list.get(0);
        else
            return null;

    }
}
